<?php


class newsListComponents extends myComponents{

	public function executeRender(){

		if($this->getAction()->getRoute()->getNewsItemObject()){

			return $this->getAction()->renderPartial('newsList/newsItemPage', array(
				'newsItem' => $this->getAction()->getRoute()->getNewsItemObject() )
			);
		}else{
			$this->node = $this->getRoute()->getObject();
			$this->pager = $this->getPager();
		}


	}



	public function getPager(){
		$pager = new sfDoctrinePager( 'NewItem', 100 );
  		$pager->setQuery( $this->getNewsQuery() );
  		$pager->setPage($this->getRequestParameter('page', 1));
  		$pager->init();

		return $pager;
	}

	public function getNewsQuery()
	{
		$q = Doctrine::getTable('NewItem')
			->createQuery('asdaksd;')
			->select('ni.*, ng.*')
			->from('NewItem ni')
			->innerJoin('ni.NewsGroup ng')
			->innerJoin('ng.StructureNewsGroup sng')
			->innerJoin('sng.Structure s')
			->where('s.id = ?',
					$this->getRoute()->getObject()->getId())
			->orderBy('ni.pri desc');

		//$q->setHydrationMode(Doctrine::HYDRATE_ARRAY);
		
		NewItemTable::commonActivityConstraints($q);
		
		
		return $q;
	}


}